import { Component, Vue } from 'vue-property-decorator'
import HelloWorld from '@/components/HelloWorld.vue' // @ is an alias to /src

@Component({
  components: {
    HelloWorld
  }
})

export default class Home extends Vue {
  private form: {
    account: string,
    password: string
  } = {
    account: 'admin',
    password: '123456'
  }
  private loginRules = {
    account: [
      { required: true, trigger: 'blur', message: '用户名不能为空！'}
    ],
    password: [
      { required: true, trigger: 'blur', message: '密码不能为空！'}
    ]
  }
  private created () {
    document.onkeyup = (e) => {
      if (e.key === 'Enter') {
        this.onSubmit()
      }
    }
  }
  private onSubmit (): void {
    (this.$refs.loginForm as any).validate((valid: boolean) => {
      if (valid) {
        this.$store.commit('SET_AUTH', { code: 1 })
        this.$router.push('./Home')
      }
    })
  }
}
